import time

from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy


class TestLoan:
    url = 'http://127.0.0.1:4723/wd/hub'
    param = {
        "deviceName": "8HJ76H49KJQKM7IF",
        "platformName": "Android",
        "platformVersion": "13",
        "appPackage": "com.duxiaoman.wallet",
        "appActivity": "com.duxiaoman.wallet.home.SplashActivity"
    }

    def apptest4(self):
        time.sleep(5)
        driver = webdriver.Remote(self.url, self.param)
        # 点击同意按钮
        driver.find_element(MobileBy.ID, "com.duxiaoman.wallet:id/protocol_dialog_pos_btn").click()
        time.sleep(5)
        # 点击拒绝按钮
        driver.find_element(MobileBy.XPATH,
                                  "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.Button[1]").click()
        time.sleep(5)
        # 点击“借钱”按钮
        driver.find_element(MobileBy.ACCESSIBILITY_ID, "借钱").click()
        time.sleep(5)
        # 填写相关信息并提交
        driver.find_element(MobileBy.ID, "com.baidu.wallet:id/et_amount").send_keys("1000")
        time.sleep(5)
        driver.find_element(MobileBy.ID, "com.baidu.wallet:id/et_period").send_keys("12")
        time.sleep(5)
        driver.find_element(MobileBy.ID, "com.baidu.wallet:id/btn_submit").click()
        time.sleep(5)
        driver.quit()


apptestcase = TestLoan()
apptestcase.apptest4()
